import { ajax, tools } from '../../js/ajax.js';

let txtName = document.getElementById('txtName');
let txtPwd = document.getElementById('txtPwd');
let btnLogin = document.getElementById('btnLogin');
let spInfo = document.getElementById('spInfo');

btnLogin.addEventListener('click', () => {
  let user = {
    username: txtName.value,
    password: tools.md5(txtPwd.value),
  };

  ajax.post('/user/auth/login', user, (data) => {
    spInfo.innerHTML = data.message;
    if (data.success) {
      // 登录成功跳转到首页
      location.href = 'main.html';
    }
  });
});
